package com.htandroid.htandroid.aty;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.htandroid.htandroid.R;
import com.htandroid.htandroid.entity.GcwxVouchsForeign;
import com.htandroid.htandroid.sys.Basenvo;
import com.htandroid.htandroid.sys.base_index;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lkp on 2015/11/29.
 */
public class Gcwx_foreign_detaillist extends base_index {
    private ArrayList<GcwxVouchsForeign> vouchsforeignslist;
    String icurrentrow;//记录上一页的当前行

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAbContentView(R.layout.layout_gcwx_inventory_detaillist);
        initview("外包材料");
        initview2();
        createrl(vouchsforeignslist);
    }

    //初始化2
    @Override
    public void initview2() {
        //获取传递的对象参数
        vouchsforeignslist = (ArrayList<GcwxVouchsForeign>) getIntent().getSerializableExtra("vouchsforeignlist");
        icurrentrow = getIntent().getExtras().getString("currentrow");
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                //从position改为id,因为过滤之后的position不正确
                intent.putExtra("listrow", String.valueOf(id));
                setResult(R.layout.layout_gcwx_inventory_detaillist / 500000, intent);  //设置返回结果
                finish();
            }
        });
    }

    public void createrl(ArrayList<GcwxVouchsForeign> cvouchsforeignlist) {
        adatperDataList.clear();
        ArrayList<Map<String, Object>> dataListForInit = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < cvouchsforeignlist.size(); i++) {
            //增加一个行选择状态初始化
            if (i == Integer.valueOf(icurrentrow)) {
                sa.getIsSelected().put(i, true);
            } else {
                sa.getIsSelected().put(i, false);
            }
            GcwxVouchsForeign vouchsForeign = new GcwxVouchsForeign();
            vouchsForeign = cvouchsforeignlist.get(i);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("index", (i + 1));
            map.put("cvouchid", "存货名称：" + vouchsForeign.getCinvname());
            map.put("cdept", "规　　格：" + vouchsForeign.getCinvstd());
            map.put("cnocheckreason", "单　　位：" + vouchsForeign.getCinvm_uint());
            map.put("ddate", "数　　量：" + Basenvo.customFormat("######.00##", vouchsForeign.getIquantity()));
            //更多数据
            map.put("data5", "单　　价：" + Basenvo.customFormat("######.00##", vouchsForeign.getIprice()));
            map.put("data6", "金　　额：" + Basenvo.customFormat("######.00##", vouchsForeign.getIamount()));
            map.put("data7", "备　　注：" + vouchsForeign.getCmemo());
            map.put("data8", "");
            dataListForInit.add(map);
        }
        toolDataProvider.initData(dataListForInit);
        loadList();
        //mHandler.sendEmptyMessage(LIST_GET_FIRST_PAGE); //加载完毕发送指令显示第一页
        //swipeRefreshLayout.setRefreshing(false);
    }
}
